from data_wash import utils
import os
import math
import datetime
import numpy as np
import re
from pandas import read_csv

result_root = os.path.abspath('result')
pre_tem_root = os.path.abspath('result/PRE+TEM')  # 临时站点数据存放
if not os.path.exists(result_root):
    os.mkdir(result_root)
if not os.path.exists(pre_tem_root):
    os.mkdir(pre_tem_root)

"""
   52533 酒 泉 3946N 
   52681 民 勤 3838N 
   52787 乌鞘岭 3712N 
   52884 皋 兰 3621N 
   53915 平 凉 3533N  
   56080 合 作 3500N 
   56096 武 都 3324N 
   57006 天 水 3435N 
   57014 天水北道区 3434N 
   """
station_latitude = np.array([[52533, 39.46],
                             [52681, 38.38],
                             [52787, 37.12],
                             [52884, 36.21],
                             [53915, 35.33],
                             [56080, 35.00],
                             [56096, 33.24],
                             [57006, 34.35],
                             [57014, 34.34]])
station_latitude_list = station_latitude.flatten().tolist()
if __name__ == '__main__':

    f = open('E:\lyf_ML_Drought\coding\ML_Drought_Prediction\meteorological_data\GANSU_MONTH_DATA\gansu_data_interpolated.txt', 'r')
    alllines = f.readlines()
    for i in range(0, len(alllines)):
        alllines[i] = alllines[i].strip('\n').split(' ')
        if i is 0:
            #  0的时候不是数据
            continue
        else:
            station = alllines[i][0]  # 站点编号
            fp = os.path.join(pre_tem_root, 'PRE+TEM' + station + '.txt')
            fw = open(fp, 'a+')
            latitude = station_latitude_list[station_latitude_list.index(int(station))+1]
            year = alllines[i][1]
            month = alllines[i][2]
            precipitation = utils.data_filter(alllines[i][9])
            temperature = utils.data_filter(alllines[i][12])
            print(year, month, latitude, precipitation, temperature)
            fw.write(str(year) + ' ' + str(month) + ' ' + str(latitude) + ' ' + str(precipitation) + ' ' + str(temperature) + '\n')
    f.close()
